home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / SecalDemo / Projects / Examples / WaveDemo.scl < prev    next >
Text File  |  1998-06-24  |  4KB  |  224 lines

  1. /******************************************************************************\
  2. **  Wave drawing demo for Secal                                               **
  3. **  Requires Kickstart 2                                                      **
  4. \******************************************************************************/
  5.  
  6.  
  7. go main;
  8.  
  9.  
  10. #-------------------------------------------------------------------------------
  11.  
  12.  
  13. include "inc/libcalls/exec.inc";
  14. include "inc/libcalls/intuition.inc";
  15. include "inc/libcalls/graphics.inc";
  16.  
  17. include "inc/utility/tagitem.inc";
  18. include "inc/intuition/screens.inc";
  19. include "inc/graphics/modeid.inc";
  20.  
  21.  
  22. def SysBase=[4.w].ul;
  23.  
  24.  
  25. /******************************************************************************\
  26. ************                      M A I N                           ************
  27. \******************************************************************************/
  28.  
  29.  
  30. obj IntuitionBase,GfxBase:ulong;
  31.  
  32. obj myscr,myscrrp:ulong;
  33. obj basex,basey:word;
  34.  
  35.  
  36. #-------------------------------------------------------------------------------
  37.  
  38.  
  39. main:
  40. call sysinit;
  41. if d0 then
  42.     call waveinit;
  43.     call wavedraw;
  44.     while [$dff016] and $400 do;        # DIRTY CHECK FOR RIGHT MOUSE BUTTON
  45.     call sysdone;
  46. ;
  47.  
  48. d0.l:=0;
  49. rts;                                                            # MAIN
  50.  
  51.  
  52.  
  53.  
  54.  
  55. #                                                                    D0=SUCCESS
  56.  
  57. sysinit:
  58. OpenLibrary("graphics.library",37); GfxBase:=d0;
  59. if GfxBase then
  60.     OpenLibrary("intuition.library",37); IntuitionBase:=d0;
  61.     if IntuitionBase then
  62.         OpenScreenTagList(0,@scrtags); myscr:=d0;
  63.         if myscr then
  64.  
  65.             a0:=myscr; myscrrp:=@Screen(a0).RastPort;
  66.             basex:=Screen(a0).Width/2-300/2;
  67.             d0:=Screen(a0).Height-(Screen(a0).BarHeight+1);
  68.             d0:=d0/2+(Screen(a0).BarHeight+1); basey:=d0-188/2+128;    # 0,0 OFFSET
  69.  
  70.             d0:=-1; go end_sysinit;        # INIT SUCCESSFULL
  71.         ;
  72.  
  73.                                                         # OTHERWISE FAILED
  74.         CloseLibrary(IntuitionBase);
  75.     ;
  76.     CloseLibrary(GfxBase);
  77. ;
  78.  
  79. d0:=0;
  80.  
  81. end_sysinit:
  82. rts;                                                            # SYSINIT
  83.  
  84.  
  85.  
  86. scrtags:
  87. dc.l SA_Depth,2;
  88. dc.l SA_Title,"Secal Wave demo";
  89. dc.l SA_Pens,@scrpens;
  90. dc.l TAG_DONE;                            # TAGS FOR OUR SCREEN
  91.  
  92. scrpens:
  93. dc.w -1;                                        # TO MAKE IT "NEW LOOK"
  94.  
  95.  
  96.  
  97.  
  98.  
  99. sysdone:
  100. CloseScreen(myscr);                        # CLOSE SCREEN
  101.  
  102. CloseLibrary(IntuitionBase);
  103. CloseLibrary(GfxBase);                # CLOSE LIBS
  104. rts;                                                            # SYSDONE
  105.  
  106.  
  107. /******************************************************************************\
  108. ************                      W A V E                           ************
  109. \******************************************************************************/
  110.  
  111.  
  112. obj hiarray[300],loarray[300]:word;            # EDGES OF THE SURFACE
  113.  
  114.  
  115. #-------------------------------------------------------------------------------
  116.  
  117.  
  118. waveinit:
  119. a0:=@hiarray; a1:=@loarray;
  120. for d0:=299 downto 0 do [a0+]:=-9999; [a1+]:=9999;;    # LO AND HI ARRAYS
  121. rts;                                                            # WAVEINIT
  122.  
  123.  
  124.  
  125.  
  126.  
  127. wavedraw:
  128. push d2\d3\d4\d5;
  129.  
  130. for d5:=0 upto 196 step 2 do
  131.     for d4:=199 downto 0 do
  132.         d2:=d4+d5 lsr 1; d3:=(d4 lsr 1-d5) asr 1;
  133.         d0:=d4-100; d1:=d5-100; call waveheight;
  134.         d3:=d3-d0;                                # CALC (U,V) ON THE DISPLAY
  135.  
  136.         a0:=@hiarray+d2.w lsl 1;
  137.         if d3>[a0] then
  138.             [a0]:=d3;
  139.             SetAPen(myscrrp,3);
  140.             WritePixel(myscrrp,basex+d2.w,basey+d3.w);
  141.         ;                                                    # DRAW HIGH PIXEL
  142.         a0:=@loarray+d2.w lsl 1;
  143.         if d3<[a0] then
  144.             [a0]:=d3;
  145.             SetAPen(myscrrp,2);
  146.             WritePixel(myscrrp,basex+d2.w,basey+d3.w);
  147.         ;                                                    # DRAW LOW PIXEL
  148.     ;                                                        # X LOOP
  149. ;                                                            # Y LOOP
  150.  
  151. pop d2\d3\d4\d5;
  152. rts;                                                            # WAVEDRAW
  153.  
  154.  
  155. #-------------------------------------------------------------------------------
  156.  
  157.  
  158. # D0=X, D1=Y                                            D0=HEIGHT
  159.  
  160. waveheight:
  161. push d2\d3;
  162. d2:=d0; d3:=d1;
  163.  
  164. d0:=d3*40; sin(d0); d1:=d0;
  165. d0:=d2*40; cos(d0);
  166. d0.l:=(d0.w*d1.w) asr 8;            # COS(X)*SIN(Y)
  167.  
  168. d1:=d2;
  169. if d1<0 then d1:=-d1;;
  170. if d1<d3 then d1:=d3;
  171. elif d1<-d3 then d1:=-d3;;            # DISTANCE
  172.  
  173. d0.l:=d0*(100-d1);
  174.  
  175. d0.l:=d0 asr 8;                                # FIXPOINT OFF
  176.  
  177. pop d2\d3;
  178. rts;                                                            # WAVEHEIGHT
  179.  
  180.  
  181.  
  182.  
  183.  
  184. #                                                                    D0=RESULT
  185.  
  186. pattern sin(source) is
  187.     push a0;
  188.  
  189.     move        source,d7;
  190.     and            $fff,d7;
  191.     lsl            1,d7;
  192.     lea            [@sincostable],a0;
  193.     move        [a0+d7.w],d0;
  194.  
  195.     pop a0;
  196. endp;                                                            # SIN
  197.  
  198.  
  199.  
  200. #                                                                    D0=RESULT
  201.  
  202. pattern cos(source) is
  203.     push a0;
  204.  
  205.     move        source,d7;
  206.     and            $fff,d7;
  207.     lsl            1,d7;
  208.     lea            [@sincostable+$800],a0;
  209.     move        [a0+d7.w],d0;
  210.  
  211.     pop a0;
  212. endp;                                                            # COS
  213.  
  214.  
  215.  
  216.  
  217.  
  218. sincostable:                        incbin "data/sincos.dat";
  219.                                                 # 1.25 SINE WAVE, 4096+1024 WORDS, 4096=1 WAVE (2*PI)
  220.  
  221.  
  222. #*******************************************************************************
  223.  
  224.